package com.bluegalaxy.nhb.snservice.core.util;

import com.bluegalaxy.nhb.snservice.domain.constant.CkConstant;
import com.bluegalaxy.nhb.snservice.domain.vo.api.ck.UserPortraitTemplateItems;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Created by IntelliJ IDEA.
 * User: ZhangMJ
 * Date: 15-5-20
 * Time: 上午8:58
 * To change this template use File | Settings | File Templates.
 */
public class ChartUtil {
    private final static int FILE_BUFFER_SIZE = 20480;


    public static void main(String[] args) {
        int count = 6000;
        int length = String.valueOf(count).length();
        System.out.println(count/5);
        System.out.println(count%5);
        System.out.println(String.format("%03X", count));
//        System.out.println(ChartUtil.dealNumber(count));


    }
    //获取位数整倍数
    public static UserPortraitTemplateItems getChart(List<Map<String,Object>> list, UserPortraitTemplateItems items) {
        String chartType = items.getChartType();
        String key = items.getParamField2();
//        UserPortraitTemplateItems items = new UserPortraitTemplateItems();

        Map<String, List<Map>> collect = list.stream().collect(Collectors.groupingBy(map->{
            Map result = map;
            if("".equals(String.valueOf(result.get(key)))){
                return "未定义";
            }else{
                return String.valueOf(result.get(key));
            }
        }));
        // Map<String, List<Map>> collect = list.stream().collect(Collectors.groupingBy(map-> map.get("usestate"));
        Map<String,Object> resultMap = new HashMap<>();
        collect.forEach((resKey,mapList)->{
            resultMap.put(resKey,mapList.size());
        });

        items.setChartType(chartType);
        switch (chartType){
            case CkConstant.chart_bar:
                getBar(resultMap,items);
                break;
            case CkConstant.chart_ring:
                getRing(resultMap,items);
                break;
            case CkConstant.chart_pie:
                getPie(resultMap,items);
                break;
            case CkConstant.chart_cate:
                getCate(resultMap,items);
                break;
            case CkConstant.chart_pillar:
                getPillar(resultMap,items);
                break;
            default:
                getBar(resultMap,items);
        }

        return items;
    }

    public static UserPortraitTemplateItems getBar(Map<String,Object> map,UserPortraitTemplateItems items){
        List ydata=new ArrayList();
        List xdata=new ArrayList();
        for(String key:map.keySet()){//keySet获取map集合key的集合  然后在遍历key即可
            String value = map.get(key).toString();//
            ydata.add(key);
            Map xMap=new HashMap();
            xMap.put("name",key);
            xMap.put("value",value);
            xdata.add(xMap);
        }
        items.setYdata(ydata);
        items.setXdata(xdata);

        return items;
    }

    public static UserPortraitTemplateItems getRing(Map<String,Object> map,UserPortraitTemplateItems items){
        List xdata=new ArrayList();
        for(String key:map.keySet()){//keySet获取map集合key的集合  然后在遍历key即可
            String value = map.get(key).toString();//
            Map xMap=new HashMap();
            xMap.put("name",key);
            xMap.put("value",value);
            xdata.add(xMap);
        }
        items.setXdata(xdata);

        return items;
    }

    public static UserPortraitTemplateItems getPie(Map<String,Object> map,UserPortraitTemplateItems items){
        List xdata=new ArrayList();
        for(String key:map.keySet()){//keySet获取map集合key的集合  然后在遍历key即可
            String value = map.get(key).toString();//
            Map xMap=new HashMap();
            xMap.put("name",key);
            xMap.put("value",value);
            xdata.add(xMap);
        }
        items.setXdata(xdata);

        return items;
    }

    public static UserPortraitTemplateItems getCate(Map<String,Object> map,UserPortraitTemplateItems items){
        // xdata: ['[20,40]','[40,60]','[60,80]'],
        List xdata=new ArrayList();
        xdata.add(new Integer[]{20,40});
        xdata.add(new Integer[]{40,60});
        xdata.add(new Integer[]{60,80});
        items.setXdata(xdata);

        List ydata=new ArrayList();
        //ydata: ['张三','李四','王五'],
        ydata.add("张三");
        ydata.add("李四");
        ydata.add("王五");
        items.setYdata(ydata);

        //data: [[0, 0, 20], [0, 1, 50], [0, 2, 80], [1, 0, 30], [1, 1, 60], [1, 2, 70],[2, 0, 40], [2, 1, 70], [2, 2, 30],]
        List zdata=new ArrayList();
        zdata.add(new Integer[]{0, 0, 20});
        zdata.add(new Integer[]{0, 1, 50});
        zdata.add(new Integer[]{0, 2, 80});
        zdata.add(new Integer[]{1, 0, 30});
        zdata.add(new Integer[]{1, 1, 60});
        zdata.add(new Integer[]{1, 2, 70});
        zdata.add(new Integer[]{2, 0, 40});
        zdata.add(new Integer[]{2, 1, 70});
        zdata.add(new Integer[]{2, 2, 30});
        items.setZdata(zdata);

        return items;
    }

    public static UserPortraitTemplateItems getPillar(Map<String,Object> map,UserPortraitTemplateItems items){
        List xdata=new ArrayList();
        for(String key:map.keySet()){//keySet获取map集合key的集合  然后在遍历key即可
            String value = map.get(key).toString();//
            Map xMap=new HashMap();
            xMap.put("name",key);
            xMap.put("value",value);
            xdata.add(xMap);
        }
        items.setXdata(xdata);

        return items;
    }


}
